<?php
/**
 * Holds class Mvc_View_Smarty
 *
 * @author daantimmer
 *
 * @package Library
 * @subpacakge Mvc
 */

/**
 * A view used to output data using the Smarty Template Engine
 *
 * @author daantimmer
 */
class Mvc_View_Smarty extends Mvc_View{

	/**
	 * @see Mvc_View_Interface::render()
	 */
	public function render() {

		$smarty = new Smarty();

		$module = $this->_module;
		$controller = strtolower(substr($this->_controller,0,strlen($this->_controller) - strlen('Controller')));
		$action = strtolower(substr($this->_action,strlen('action')));

		$compiledir = APP . 'tpl' . DIRECTORY_SEPARATOR . strtolower($module) . DIRECTORY_SEPARATOR . 'bin';
		$cachedir= APP . 'tpl' . DIRECTORY_SEPARATOR . strtolower($module) . DIRECTORY_SEPARATOR . 'cache';
		$srcdir = APP . 'tpl' . DIRECTORY_SEPARATOR . strtolower($module) . DIRECTORY_SEPARATOR . 'src';

		$smarty->compile_dir = $compiledir;
// 		$smarty->cache_dir = $cachedir;
		$smarty->template_dir = $srcdir;

		$page = $controller . DIRECTORY_SEPARATOR . $action . '.html';
		$views = APP . 'views' . DIRECTORY_SEPARATOR . $module;

		$smarty->assign("page",$page);
		$smarty->assign("views",$views);

		foreach($this->_var as $key => $var)
			$smarty->assign($key,$var);

// 		$smarty->register_modifier('encodeV',array("Util", 'encodeV'));
// 		$smarty->register_modifier('encodePath',array("Util", 'encodePath'));
// 		$smarty->register_modifier('encodeImage',array("Util", 'encodeImage'));
// 		$smarty->register_modifier('encodeProduct',array("Util", 'encodeProduct'));

		return $smarty->fetch($this->_template.'.html');
	}
}